//
//  VSLaLaViewController.m
//  Project_A
//
//  Created by dlios on 15/7/23.
//  Copyright (c) 2015年 zhoukaidong. All rights reserved.
//

#import "VSLaLaViewController.h"
#import "BaseHeader.h"
@interface VSLaLaViewController () <UITextViewDelegate, UITextFieldDelegate, UIAlertViewDelegate>
@property (nonatomic , retain)UIButton *VSback;
@property (nonatomic, retain) UIButton *VSRightButton;
@property (nonatomic, retain) UILabel *placeLabel;
@property (nonatomic, retain) UITextView *backField;
@property (nonatomic, retain) UITextField *telField;

@end

@implementation VSLaLaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    if (self.section_row == 1) {
        UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
        tapGr.cancelsTouchesInView = NO;
        [self.view addGestureRecognizer:tapGr];
        [self createScrollView];
    }
    
    [self creatNavi];
}

-(void)viewTapped:(UITapGestureRecognizer*)tapGr
{
    [self.backField resignFirstResponder];
    [self.telField resignFirstResponder];
    if (self.backField.text.length == 0 || self.telField.text.length == 0) {
        self.VSRightButton.alpha = 0.7;
    }
}

-(void)creatNavi
{
    UIView *naview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20 )];
    naview.backgroundColor = NAVCOLOR;
    [self.view addSubview:naview];
    UILabel *Navlabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 44)];
    Navlabel.backgroundColor = NAVCOLOR;
    if (self.section_row == 1) {
        Navlabel.text = @"意见反馈";
    } else {
        Navlabel.text = @"关于我们";
    }
    
    Navlabel.font = [UIFont systemFontOfSize:21];
    Navlabel.textColor = [UIColor whiteColor];
    Navlabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:Navlabel];
    [self.view bringSubviewToFront:Navlabel];
    
    self.VSback = [UIButton buttonWithType:UIButtonTypeCustom];
    self.VSback.backgroundColor = [UIColor clearColor];
    self.VSback.frame = CGRectMake(5  , 25, 32, 32);
    [self.VSback setBackgroundImage:[UIImage imageNamed:@"iconfont-xiangzuo@2x"] forState:UIControlStateNormal];
    [self.VSback addTarget:self action:@selector(getBack) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.VSback];
    [self.VSback bringSubviewToFront:self.VSback];
    
    if (self.section_row == 1) {
        self.VSRightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.VSRightButton.frame = CGRectMake(SCREEN_WIDTH - 65, 25, 60, 32);
        self.VSRightButton.titleLabel.textColor = [UIColor whiteColor];
        self.VSRightButton.titleLabel.font = [UIFont systemFontOfSize:15];
        [self.VSRightButton setTitle:@"完成" forState:(UIControlStateNormal)];
        [self.VSRightButton addTarget:self action:@selector(finishAction) forControlEvents:(UIControlEventTouchUpInside)];
        [self.view addSubview:self.VSRightButton];
        self.VSRightButton.alpha = 0.7;
    }
    
    
}


- (void)finishAction
{
    if (self.backField.text.length != 0 && self.telField.text.length != 0) {
        [self.VSRightButton setTitle:@"完成" forState:(UIControlStateHighlighted)];
        self.VSRightButton.alpha = 1;
        UILabel *view1 = [[[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - 100, SCREEN_HEIGHT / 2 - SCREEN_HEIGHT / 5, 200, 80)] autorelease];
        view1.backgroundColor = [UIColor blackColor];
        view1.text = @"发送反馈成功";
        view1.font = [UIFont systemFontOfSize:20];
        view1.textColor = [UIColor whiteColor];
        [view1.layer setCornerRadius:10];
        view1.clipsToBounds = YES;
        view1.alpha = 0.5;
        view1.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:view1];
        [self.view bringSubviewToFront:view1];
        
        [UIView animateWithDuration:1.5f animations:^{
            view1.alpha = 0;

        }];
        
    }
    
   
}

-(void)getBack
{
    [self.navigationController popViewControllerAnimated:YES];
    
    
}

- (void)createScrollView
{
    
    
    UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 110)];
    scroll.backgroundColor = [UIColor colorWithRed:219 / 255.0 green:219 / 255.0 blue:219 / 255.0 alpha:1];
    [self.view addSubview:scroll];
    scroll.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - 100);
    
    UILabel *backLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 30 , 80, 25)];
    backLabel.text = @"反馈内容";
    backLabel.alpha = 0.7;
    [scroll addSubview:backLabel];
    self.backField = [[UITextView alloc]initWithFrame:CGRectMake(10, backLabel.frame.origin.y + backLabel.frame.size.height + 8, SCREEN_WIDTH - 20, SCREEN_HEIGHT / 5)];
    self.backField.backgroundColor = [UIColor whiteColor];
    self.backField.font = [UIFont systemFontOfSize:18];
    self.backField.layer.borderWidth = 0.25;
    self.backField.layer.cornerRadius = 6;
    self.backField.layer.masksToBounds = YES;
    self.backField.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    self.backField.delegate = self;
    self.backField.layer.borderColor = [UIColor blackColor].CGColor;
    self.backField.textAlignment = NSTextAlignmentLeft;
    [scroll addSubview:self.backField];
    
    
    self.placeLabel = [[[UILabel alloc] init] autorelease];
    self.placeLabel.frame = CGRectMake(20, self.backField.frame.origin.y + 13, SCREEN_WIDTH, 20);
    self.placeLabel.text = @" 我们很需要你的意见和建议~";
    self.placeLabel.backgroundColor = [UIColor clearColor];
    self.placeLabel.font = [UIFont systemFontOfSize:18];
    self.placeLabel.alpha = 0.418;
    self.placeLabel.enabled = NO;
    [scroll addSubview:self.placeLabel];
    
    
    
    
    UILabel *telLabel = [[[UILabel alloc]initWithFrame:CGRectMake(backLabel.frame.origin.x, self.backField.frame.origin.y + self.backField.frame.size.height + 30, backLabel.frame.size.width, backLabel.frame.size.height)] autorelease];
    telLabel.text = @"联系方式";
    telLabel.alpha = 0.7;
    [scroll addSubview:telLabel];
    self.telField = [[[UITextField alloc]initWithFrame:CGRectMake(10, telLabel.frame.origin.y + telLabel.frame.size.height + 8, SCREEN_WIDTH - 20 , 50)] autorelease];
    self.telField.backgroundColor = [UIColor whiteColor];
    self.telField.layer.borderWidth = 0.25;
    self.telField.layer.cornerRadius = 6;
    self.telField.layer.masksToBounds = YES;
    self.telField.layer.borderColor = [UIColor blackColor].CGColor;
    self.telField.placeholder = @"  电话/邮箱/微博/QQ";
    self.telField.font = [UIFont systemFontOfSize:18];
    [scroll addSubview:self.telField];
    
}


- (void)textViewDidChange:(UITextView *)textView
{
    if (textView.text.length == 0) {
        self.placeLabel.text = @" 我们很需要你的意见和建议~";
    } else {
        self.placeLabel.text = @"";
    }
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.telField resignFirstResponder];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
